/* Copyright 2008 Milko Slavov
 * This file is part of GEH.
 * GEH is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * GEH is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * See <http://www.gnu.org/licenses/>.
*/

package com.geh.event.example;

import java.io.InvalidObjectException;

import com.geh.event.EventListener;
import com.geh.event.ExceptionHandler;

public class ValueListener
{
   @EventListener("onCreate") 
   public void handleCreateEvent(ValueEvent event) {
      System.out.println("value create: " + event.getNewValue());
   }

   @EventListener("onRemove") 
   public void handleRemoveEvent(ValueEvent event) throws InvalidObjectException {
      System.out.println("value removed: " + event.getOldValue());
      throw new InvalidObjectException("Tin tiri min tiri");
   }

   @ExceptionHandler({"java.io.InvalidObjectException"}) 
   public void handleError(Throwable t) {
      t.printStackTrace();
   }

   public static void main (String[] args) {
      ValueHolder provider = new ValueHolder();
      ValueListener listener = new ValueListener();
      provider.addValueListener(listener);
      provider.createValue("New value");
      provider.updateValue("Value update");
      provider.removeValue();
      
   }
   
}
